/**    
 * @Description: 博客园地址：https://www.cnblogs.com/zumengjie/      
 * @author: 顶风少年   
 * @date: 2021年4月5日 下午3:18:27
 */

package datang.dtdb.transaction.managed;

import java.sql.Connection;
import java.util.Properties;

import javax.sql.DataSource;

import datang.dtdb.session.TransactionIsolationLevel;
import datang.dtdb.transaction.Transaction;
import datang.dtdb.transaction.TransactionFactory;

/**
 * 不关注事务，默认的自动关闭
 */
public class ManagedTransactionFactory implements TransactionFactory {

	private boolean closeConnection;

	/**
	 * 设置属性
	 */
	@Override
	public void setProperties(Properties props) {
		if (props != null) {
			String closeConnectionProperty = props.getProperty("closeConnection");
			if (closeConnectionProperty != null) {
				closeConnection = Boolean.valueOf(closeConnectionProperty);
			}
		}
	}

	@Override
	public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
		return new ManagedTransaction(dataSource, level, closeConnection);
	}

}
